package com.ruoyi.project.king.specification.controller;

import java.util.List;

import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.king.specification.domain.TSpecification;
import com.ruoyi.project.king.specification.service.ITSpecificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 产品规格Controller
 * 
 * @author ruoyi
 * @date 2020-05-19
 */
@Controller
@RequestMapping("/product/specification")
public class TSpecificationController extends BaseController
{
    private String prefix = "/cms/product/specification";

    @Autowired
    private ITSpecificationService tSpecificationService;


    @GetMapping()
    public String specification()
    {
        return prefix + "/specification";
    }

    /**
     * 查询产品规格列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSpecification tSpecification)
    {
        startPage();
        List<TSpecification> list = tSpecificationService.selectTSpecificationList(tSpecification);
        return getDataTable(list);
    }

    /**
     * 导出产品规格列表
     */

    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSpecification tSpecification)
    {
        List<TSpecification> list = tSpecificationService.selectTSpecificationList(tSpecification);
        ExcelUtil<TSpecification> util = new ExcelUtil<TSpecification>(TSpecification.class);
        return util.exportExcel(list, "specification");
    }

    /**
     * 新增产品规格
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品规格
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSpecification tSpecification)
    {
        return toAjax(tSpecificationService.insertTSpecification(tSpecification));
    }

    /**
     * 修改产品规格
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TSpecification tSpecification = tSpecificationService.selectTSpecificationById(id);
        mmap.put("tSpecification", tSpecification);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品规格
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSpecification tSpecification)
    {
        return toAjax(tSpecificationService.updateTSpecification(tSpecification));
    }

    /**
     * 删除产品规格
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tSpecificationService.deleteTSpecificationByIds(ids));
    }
}
